<header class="bg-white b-b p-xs">
    <h4>Membership Approvals</h4>
</header>

<section class='hbox stretch'>
    <aside class="aside-sm">

    </aside>

    <aside class="aside-xl">
        <section class='scrollable'>
            <input type='hidden' id='join_approval_url' value='<?php echo $this->Html->url(array('action' => 'approve')); ?>'
                   <ul class="list-group m-b-none m list-group-lg list-group-sp">
                <!-- USE FOR LOOP WHEN DATA IS AVAILABLE-->

                <?php
                foreach ($feed as $record) {
                    if (!isset($record["Member"]['id'])) {
                        continue;
                    }
                    ?>
                    <li class="list-group-item">

                        <a href="#" class="thumb-sm pull-left m-r-sm">
                            <?php if (isset($record['OrganisationMemberImage']['MemberImage']['url']) && $record['OrganisationMemberImage']['MemberImage']['url']) { ?>
                                <img src="<?php echo $this->Html->url($record['OrganisationMemberImage']['MemberImage']['thumb_url']); ?>" class="img-circle">
                            <?php } else { ?>
                                <img src="<?php echo $this->Html->url('/img/admin/no-image.gif'); ?>" class="img-circle">
                            <?php } ?>
                        </a>

                        <a class="profile_link" href="<?php echo $this->Html->url(array('action' => 'member_details', $record['Member']['id'])); ?>" class="clear">
                            <small class="pull-right">
                                <?php
                                $created = $record['OrganisationMember']['created'];
                                echo $this->Time->timeAgoInWords($created, array(
                                    'accuracy' => array(
                                        'month' => 'month',
                                        'day' => 'day',
                                        'week' => 'weeks'
                                    )
                                ));
                                ?>
                            </small>
                            <strong class="block"><?php echo $record['Member']['first_name'] . ' ' . $record['Member']['last_name']; ?></strong>
                            <small class='muted'>
                                <?php
                                switch ($record['OrganisationMember']['source']) {
                                    case 'admin':
                                        echo "Profile created by " . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                        break;

                                    case 'public':
                                        if ($record['OrganisationMember']['approved'] == 1) {
                                            echo 'Join request approved by ' . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                        } else {
                                            echo "Asked to join organisation.";

                                            echo "<span class='pull-right'>";
                                            echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-success' data-member-id='{$record['Member']['id']}' data-action='approve'><i class='fa fa-check'></i> Approve</button>";
                                            echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-danger' data-member-id='{$record['Member']['id']}' data-action='decline'><i class='fa fa-times'></i> Decline</button>";
                                            echo "</span>";
                                        }
                                        break;

                                    case 'registration':
                                        if ($record['OrganisationMember']['approved'] == 1) {
                                            echo 'Registration approved by ' . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                        } else {
                                            echo "Registered with organisation.";

                                            echo "<span class='pull-right'>";
                                            echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-success' data-member-id='{$record['Member']['id']}' data-action='approve'><i class='fa fa-check'></i> Approve</button>";
                                            echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-danger' data-member-id='{$record['Member']['id']}' data-action='decline'><i class='fa fa-times'></i> Decline</button>";
                                            echo "</span>";
                                        }
                                        break;

                                    default:
                                        echo "Membership created";
                                        break;
                                }
                                ?>
                            </small>
                        </a>
                    </li>
                <?php } ?>
            </ul>
        </section>
    </aside>
    
    <aside class="aside-sm"></aside>
</section>

<?php echo $this->Html->script('app/views/organisations/dashboard/feed.js'); ?>